package com.test.daily.leetcode.y2022.m06.day0618.v01;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/6/18 上午 08:53
 * @version: 1.0
 */
public class Solution {

    public static int[] getNextArray(int[] str2){
        int N = str2.length;
        int[] nexts = new int[N];
        nexts[0] = -1;
        nexts[1] = 0;
        int cnt = 0;
        int i = 2;
        while(i < N){
            if(str2[i] == str2[cnt]){
                nexts[i++] = ++cnt;
            } else if(cnt > 0){
                cnt = nexts[cnt];
            } else {
                nexts[i++] = 0;
            }
        }
        return nexts;
    }
}
